package com.spring_mysql_redis.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@PropertySource(value = "classpath:application.yml")
@Configuration
public class FanoutRabbitConfig {

    @Value("${spring.rabbitmq.modules.queue.name}")
    private String fanout;
    /**
     * 定义队列
     * @return
     */
    @Bean
    public Queue aMessage() {
        return new Queue(this.fanout);
    }

    /**
     * 定义队列B
     * @return
     */
//    @Bean
//    public Queue bMessage() {
//        return new Queue("q_fanout_B");
//    }

    /**
     * 定义交换机
     * @return
     */
    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange("myfanoutExchange");
    }

    /**
     * 将队列A和交换机进行绑定
     * @return
     */
    @Bean
    Binding bindingExchangeA() {
        return BindingBuilder.bind(aMessage()).to(fanoutExchange());
    }

    /**
     * 将队列B和交换机进行绑定
     * @return
     */
//    @Bean
//    Binding bindingExchangeB() {
//        return BindingBuilder.bind(bMessage()).to(fanoutExchange());
//    }
}